package com.aaa.system.controller.api;

import com.aaa.entity.Role;
import com.aaa.entity.User;
import com.aaa.system.aop.annotation.Log;
import com.aaa.system.service.RoleService;
import com.aaa.system.service.UserService;
import com.aaa.system.vo.RoleVo;
import com.aaa.system.vo.UserVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @program: his-open-parent
 * @description:
 * @author: 闫克起2
 * @create: 2023-03-20 11:05
 **/
@RestController
@RequestMapping("system/api/role")
public class ApiRoleController {

    @Autowired
    private RoleService roleService;
    @GetMapping("/list")
    public Result<List<Role>> list(){
        return roleService.getAll();
    }

    @GetMapping("getByUserId/{userId}")
    public Result<Map<String,Object>> getByUserId(@PathVariable Long userId){
        return roleService.findByUserId(userId);
    }

    @PostMapping("confirmRole")
    @Log(title = "确认分配角色",business_type = "系统业务")
    public Result<String> confirmRole(Long userId,Long[] roleIds){
        return  roleService.confirmRole(userId,roleIds);
    }

    @PostMapping("list/{currentPage}/{pageSize}")
    public Result<IPage<Role>> list(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody RoleVo roleVo
    ){
        return roleService.getByPage(currentPage,pageSize,roleVo);
    }

}
